home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Mark Pilgrim / Ghost 1.0 / source / Ghost ƒ / Ghost code / ghost graphics.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-30  |  8.1 KB  |  328 lines  |  [TEXT/KAHL]

  1. /**********************************************************************\
  2.  
  3. File:        ghost graphics.c
  4.  
  5. Purpose:    This module handles drawing the Ghost playing window.
  6.  
  7.  
  8.  
  9. Ghost -=- a classic word-building challenge
  10. Copyright (C) 1993 Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "ghost globals.h"
  30. #include "ghost graphics.h"
  31. #include "msg environment.h"
  32.  
  33. void DrawBoardColor(void)
  34. {
  35.     RGBColor    oldForeColor, oldBackColor;
  36.     GrafPtr        curPort;
  37.     Rect        space;
  38.     int            i,j;
  39.     Boolean        ghost;
  40.     
  41.     GetForeColor(&oldForeColor);
  42.     GetBackColor(&oldBackColor);
  43.     
  44.     GetPort(&curPort);
  45.     EraseRect(&(curPort->portRect));
  46.     
  47.     if (gShowMessageBox)
  48.         DrawMessage();
  49.     
  50.     TextFont(geneva);
  51.     TextSize(9);
  52.     
  53.     SetRect(&space, 40, 10, 72, 42);
  54.     for (i=0; i<((gNumPlayers<5) ? gNumPlayers : 5); i++)
  55.     {
  56.         if (gPlayOrderIndex[i]>=gNumHumanPlayers)
  57.         {
  58.             PlotCIcon(&space, gColorIcons[gComputerIconIndex[gPlayOrderIndex[i]-gNumHumanPlayers]]);
  59.             ghost=(gComputerPlayerScore[gPlayOrderIndex[i]-gNumHumanPlayers]==5);
  60.         }
  61.         else
  62.         {
  63.             PlotCIcon(&space, gColorIcons[gHumanIconIndex[gPlayOrderIndex[i]]]);
  64.             ghost=(gHumanPlayerScore[gPlayOrderIndex[i]]==5);
  65.         }
  66.  
  67.         DrawNameAndScore(i, gPlayOrderIndex[i], ghost);
  68.                 
  69.         space.left+=72;
  70.         space.right+=72;
  71.     }
  72.  
  73.     if (gNumPlayers>5)
  74.     {
  75.         SetRect(&space, 40, 76, 72, 108);
  76.         for (i=5; i<gNumPlayers; i++)
  77.         {
  78.             if (gPlayOrderIndex[i]>=gNumHumanPlayers)
  79.             {
  80.                 PlotCIcon(&space, gColorIcons[gComputerIconIndex[gPlayOrderIndex[i]-gNumHumanPlayers]]);
  81.                 ghost=(gComputerPlayerScore[gPlayOrderIndex[i]-gNumHumanPlayers]==5);
  82.             }
  83.             else
  84.             {
  85.                 PlotCIcon(&space, gColorIcons[gHumanIconIndex[gPlayOrderIndex[i]]]);
  86.                 ghost=(gHumanPlayerScore[gPlayOrderIndex[i]]==5);
  87.             }
  88.             DrawNameAndScore(i, gPlayOrderIndex[i], ghost);
  89.             
  90.             space.left+=72;
  91.             space.right+=72;
  92.         }
  93.     }
  94.     
  95.     if (gTheWord[0]!=0x00)
  96.     {
  97.         TextFont(10119);
  98.         TextFace(0);
  99.         TextSize(48);
  100.         MoveTo(200-(StringWidth(gTheWord)/2), 230);
  101.         DrawString(gTheWord);
  102.     }
  103.     
  104.     RGBForeColor(&oldForeColor);
  105.     RGBBackColor(&oldBackColor);
  106. }
  107.  
  108. void DrawBoardBW(void)
  109. {
  110.     GrafPtr        curPort;
  111.     Rect        space;
  112.     int            i,j;
  113.     Boolean        ghost;
  114.     
  115.     GetPort(&curPort);
  116.     
  117.     EraseRect(&(curPort->portRect));
  118.  
  119.     if (gShowMessageBox)
  120.         DrawMessage();
  121.     
  122.     TextFont(geneva);
  123.     TextSize(9);
  124.     
  125.     SetRect(&space, 40, 10, 72, 42);
  126.     for (i=0; i<((gNumPlayers<5) ? gNumPlayers : 5); i++)
  127.     {
  128.         if (gPlayOrderIndex[i]>=gNumHumanPlayers)
  129.         {
  130.             PlotIcon(&space, gBWIcons[gComputerIconIndex[gPlayOrderIndex[i]-gNumHumanPlayers]]);
  131.             ghost=(gComputerPlayerScore[gPlayOrderIndex[i]-gNumHumanPlayers]==5);
  132.         }
  133.         else
  134.         {
  135.             PlotIcon(&space, gBWIcons[gHumanIconIndex[gPlayOrderIndex[i]]]);
  136.             ghost=(gHumanPlayerScore[gPlayOrderIndex[i]]==5);
  137.         }
  138.  
  139.         DrawNameAndScore(i, gPlayOrderIndex[i], ghost);
  140.                 
  141.         space.left+=72;
  142.         space.right+=72;
  143.     }
  144.  
  145.     if (gNumPlayers>5)
  146.     {
  147.         SetRect(&space, 40, 76, 72, 108);
  148.         for (i=5; i<gNumPlayers; i++)
  149.         {
  150.             if (gPlayOrderIndex[i]>=gNumHumanPlayers)
  151.             {
  152.                 PlotIcon(&space, gBWIcons[gComputerIconIndex[gPlayOrderIndex[i]-gNumHumanPlayers]]);
  153.                 ghost=(gComputerPlayerScore[gPlayOrderIndex[i]-gNumHumanPlayers]==5);
  154.             }
  155.             else
  156.             {
  157.                 PlotIcon(&space, gBWIcons[gHumanIconIndex[gPlayOrderIndex[i]]]);
  158.                 ghost=(gHumanPlayerScore[gPlayOrderIndex[i]]==5);
  159.             }
  160.             DrawNameAndScore(i, gPlayOrderIndex[i], ghost);
  161.             
  162.             space.left+=72;
  163.             space.right+=72;
  164.         }
  165.     }
  166.     
  167.     if (gTheWord[0]!=0x00)
  168.     {
  169.         TextFont(10119);
  170.         TextFace(0);
  171.         TextSize(48);
  172.         MoveTo(200-(StringWidth(gTheWord)/2), 230);
  173.         DrawString(gTheWord);
  174.     }
  175. }
  176.  
  177. void DrawNameAndScore(int i, int index, Boolean ghost)
  178. {
  179.     int                cx,y;
  180.     Str255            tempStr;
  181.     int                j;
  182.     
  183.     tempStr[0]=0x00;
  184.     
  185.     cx=56+(i%5)*72;
  186.     y=52+((i>=5) ? 66 : 0);
  187.     
  188.     if (index>=gNumHumanPlayers)
  189.         for (j=((char*)(*(gIconNames[gComputerIconIndex[index-gNumHumanPlayers]])))[0]; j>=0; j--)
  190.             tempStr[j]=((char*)(*(gIconNames[gComputerIconIndex[index-gNumHumanPlayers]])))[j];
  191.     else
  192.         for (j=((char*)(*(gHumanName[index])))[0]; j>=0; j--)
  193.             tempStr[j]=((char*)(*(gHumanName[index])))[j];
  194.  
  195.     if (ghost)
  196.     {
  197.         tempStr[0]+=2;
  198.         for (j=tempStr[0]-1; j>1; j--)
  199.             tempStr[j]=tempStr[j-1];
  200.         tempStr[1]='(';
  201.         tempStr[tempStr[0]]=')';
  202.     }
  203.     
  204.     MoveTo(cx-(StringWidth(tempStr)/2), y);
  205.     DrawString(tempStr);
  206.  
  207.     y+=12;
  208.     TextFace(bold);
  209.  
  210.     tempStr[1]='G';    tempStr[2]='H';    tempStr[3]='O';    tempStr[4]='S';    tempStr[5]='T';
  211.     if (index>=gNumHumanPlayers)
  212.         tempStr[0]=gComputerPlayerScore[index-gNumHumanPlayers];
  213.     else
  214.         tempStr[0]=gHumanPlayerScore[index];
  215.     
  216.     MoveTo(cx-(StringWidth(tempStr)/2), y);
  217.     DrawString(tempStr);
  218.     TextFace(0);
  219. }
  220.  
  221. void DrawMessage(void)
  222. {
  223.     Rect            theRect;
  224.     int                j;
  225.     int                index;
  226.     int                iconIndex;
  227.     
  228.     SetRect(&theRect, 19, 142, 381, 161);
  229.     EraseRect(&theRect);
  230.     FrameRect(&theRect);
  231.     SetRect(&theRect, 22, 161, 383, 163);
  232.     FillRect(&theRect, black);
  233.     SetRect(&theRect, 381, 144, 383, 161);
  234.     FillRect(&theRect, black);
  235.  
  236.     if (gStatus!=kNewPlayer)
  237.     {
  238.         gTheMessage[0]=0x00;
  239.         if (gStatus==kWonChallenge)
  240.             AddToMessage("\pThe dictionary search came up empty!");
  241.         else if (gStatus==kLostChallenge)
  242.             AddToMessage("\pThe dictionary search came up with this word:");
  243.         else
  244.         {
  245.             index=gPlayOrderIndex[gCurrentPlayer];
  246.             if (index>=gNumHumanPlayers)
  247.             {
  248.                 for (j=((char*)(*(gIconNames[gComputerIconIndex[index-gNumHumanPlayers]])))[0]; j>=0; j--)
  249.                     gTheMessage[j]=((char*)(*(gIconNames[gComputerIconIndex[index-gNumHumanPlayers]])))[j];
  250.                 if (!gInProgress)
  251.                     AddToMessage("\p is the winner!");
  252.                 else if (gStatus==kIsChallenging)
  253.                     AddToMessage("\p challenges -- consulting dictionary...");
  254.                 else if (gStatus==kJustLost)
  255.                     AddToMessage("\p is out of the game!");
  256.                 else if (gStatus==kJustGotALetter)
  257.                 {
  258.                     switch (gComputerPlayerScore[index-gNumHumanPlayers])
  259.                     {
  260.                         case 0x01:    AddToMessage("\p gets a “G” !"); break;
  261.                         case 0x02:    AddToMessage("\p gets an “H” !"); break;
  262.                         case 0x03:    AddToMessage("\p gets an “O” !"); break;
  263.                         case 0x04:    AddToMessage("\p gets an “S” !"); break;
  264.                         case 0x05:    AddToMessage("\p is out of the game!"); break;
  265.                     }
  266.                 }
  267.                 else
  268.                 {
  269.                     if (gTheWord[0]==0x00)
  270.                     {
  271.                         AddToMessage("\p is plotting ");
  272.                         iconIndex=gComputerIconIndex[index-gNumHumanPlayers];
  273.                         if ((iconIndex==0) || (iconIndex==2) || (iconIndex==22))
  274.                             AddToMessage("\pher");
  275.                         else
  276.                             AddToMessage("\phis");
  277.                         AddToMessage("\p first move...");
  278.                     }
  279.                     else
  280.                         AddToMessage("\p is thinking...");
  281.                 }
  282.             }
  283.             else
  284.             {
  285.                 for (j=((char*)(*(gHumanName[index])))[0]; j>=0; j--)
  286.                     gTheMessage[j]=((char*)(*(gHumanName[index])))[j];
  287.                 if (!gInProgress)
  288.                     AddToMessage("\p is the winner!");
  289.                 else if (gStatus==kIsChallenging)
  290.                     AddToMessage("\p challenges -- consulting dictionary...");
  291.                 else if (gStatus==kJustLost)
  292.                     AddToMessage("\p is out of the game!");
  293.                 else if (gStatus==kJustGotALetter)
  294.                 {
  295.                     switch (gHumanPlayerScore[index])
  296.                     {
  297.                         case 0x01:    AddToMessage("\p gets a “G” !"); break;
  298.                         case 0x02:    AddToMessage("\p gets an “H” !"); break;
  299.                         case 0x03:    AddToMessage("\p gets an “O” !"); break;
  300.                         case 0x04:    AddToMessage("\p gets an “S” !"); break;
  301.                         case 0x05:    AddToMessage("\p is out of the game!"); break;
  302.                     }
  303.                 }
  304.                 else
  305.                 {
  306.                     if (gTheWord[0]==0x00)
  307.                         AddToMessage("\p, please type a letter to start a new word.");
  308.                     else
  309.                         AddToMessage("\p, please add a letter to this word.");
  310.                 }
  311.             }
  312.         }
  313.     }
  314.     
  315.     TextFont(geneva);
  316.     TextSize(9);
  317.     MoveTo(200-StringWidth(gTheMessage)/2, 155);
  318.     DrawString(gTheMessage);
  319. }
  320.  
  321. void AddToMessage(Str255 theString)
  322. {
  323.     int                i;
  324.     
  325.     for (i=1; i<=theString[0]; i++)
  326.         gTheMessage[++gTheMessage[0]]=theString[i];
  327. }
  328.